﻿function ShowAjaxError(e, prex) {
	if (e != null) {
		if (prex instanceof String) {
			prex += '：';
		} else {
			prex = "";
		}
		var msg = "";
		if (e.responseText) {
			msg = prex + e.responseText;
		} else {
			msg = prex + e.statusText;
		}
		if (msg.length > 600) {
			$.messager.alert({
				title: '提示',
				maximizable: true, resizable: true,
				msg: '<div style="height:450px;">' + msg + '</div>',
				width: 800
			});
		} else {
			$.messager.alert('错误', msg, 'error');
		}
	}
}

///加载对象
function LoadObject(id, url, callback) {
	if ((typeof (id) == "number" && id > 0) || (typeof (id) == "string" && $.IsNullOrEmpty(id) == false)) {
		if (!url.endsWith("/")) { url = url + "/" + id; }
		else { url = url + id; }

		$.ajax({
			method: "GET",
			url: url,
			success: callback,
			error: function (e) {
				ShowAjaxError(e);
			}
		});
	}
}

//获取对象(独立参数)
function GetObject(id, url, force) {
	if ((typeof (id) == "number" && id > 0) || (typeof (id) == "string" && $.IsNullOrEmpty(id) == false)) {
		if (!url.endsWith("/")) { url = url + "/" + id; }
		else { url = url + id; }

		return $.JC(url).Get3(url, null, function (k) {
			var model = null;
			$.ajax({
				async: false,
				method: 'GET',
				url: url,
				success: function (data) {
					if (data !== null) {
						model = data;
					}
				}
			});
			return model;
		}, force);
	}

	return null;
}

//获取对象(URL中带参数)
function GetUrlObject(url, force) {
	return $.JC(url).Get3(url, null, function (k) {
		var model = null;
		$.ajax({
			async: false,
			method: 'GET',
			url: url,
			success: function (data) {
				if (data !== null) {
					model = data;
				}
			}
		});
		return model;
	}, force);
}
